package com.example.wm_mbp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.wm_mbp.common.R;
import com.example.wm_mbp.model.Setmeal;
import com.example.wm_mbp.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * ClassName: SetmealController
 * Package: com.example.wm_mbp.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-03-15
 * Time: 23:04
 */
@RestController
@RequestMapping("/setmeal")
public class SetMealController {


    @Autowired
    private SetmealService setmealService;

    //GET
    //http://localhost:8080/setmeal/page?page=1&pageSize=10&name=hah
    //套餐管理的 分页查询
    @GetMapping("/page")
    public R getSetmealPage(Integer page,Integer pageSize,String name){
        //构造分页构造器
        Page<Setmeal> page1 = new Page<>(page,pageSize);

        //构造条件构造器
        LambdaQueryWrapper<Setmeal> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(name),Setmeal::getName,name);
        //asc 升序
        queryWrapper.orderByAsc(Setmeal::getId);

        //查询
        setmealService.page(page1,queryWrapper);

        return R.success(page1);

        //分页查询的第二种 方式 不用创建IPage对象 page对象 实现了IPage接口
        //直接使用 service层提供的方法page分页查询的方法 传入 分页构造器 和 条件构造器


    }

}
